//package approval.dao;
//
//import java.sql.ResultSet;
//import java.util.ArrayList;
//import java.util.Iterator;
//import java.util.List;
//
//import javax.faces.bean.ManagedBean;
//import javax.faces.bean.ManagedProperty;
//import javax.faces.bean.SessionScoped;
//import javax.faces.component.UIColumn;
//import javax.faces.component.UIComponent;
//import javax.faces.component.UIViewRoot;
//import javax.faces.component.html.HtmlSelectBooleanCheckbox;
//import javax.faces.context.FacesContext;
//import javax.faces.event.ActionEvent;
//import javax.faces.event.AjaxBehaviorEvent;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//import org.richfaces.component.UIExtendedDataTable;
//
//import resource.pojo.Approvedoc;
//import model.util.UtilInitLang;
//import models.pojo.Employee;
//import models.util.MySqlDataAccessHelper;
//
//@ManagedBean(name = "newListDocDAO")
//@SessionScoped
//public class NewListDocDAO {
//	@ManagedProperty(value = "#{utilInitLang.getClassEntity()}")
//	private UtilInitLang utilInitLang;
//	MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();
//	private int numNewDoc;
//	private ArrayList<Approvedoc> allNewDoc = new ArrayList<Approvedoc>();
//	private ArrayList<Approvedoc> allDocSelect = new ArrayList<Approvedoc>();
//	// private String scriptDbClickNewDoc;
//	private int currentIndex;
//	private String script = "";
//	private Approvedoc currentSelectApprovedoc;
//	private String strErr;
//	private boolean check = false;
//
//	public NewListDocDAO getClassEntity() {
//		return this;
//	}
//
//	public UtilInitLang getUtilInitLang() {
//		return utilInitLang;
//	}
//
//	public void setUtilInitLang(UtilInitLang utilInitLang) {
//		this.utilInitLang = utilInitLang;
//	}
//
//	public MySqlDataAccessHelper getMysql() {
//		return mysqlHelper;
//	}
//
//	public void setMysql(MySqlDataAccessHelper mysql) {
//		this.mysqlHelper = mysql;
//	}
//
//	public NewListDocDAO() {
//		
//	}
//
//	public int getNumNewDoc() {
//		try {
//			mysqlHelper.open();
//			FacesContext f = FacesContext.getCurrentInstance();
//			HttpSession ss = (HttpSession) f.getExternalContext().getSession(
//					true);
//			Employee em = (Employee) ss.getAttribute("Employee");
//			String sql = "select count(*) from approvedoc where ISNULL(IDGroupApprove) and IDEmployee='"
//					+ em.getIdemployee() + "'";
//			ResultSet rs = mysqlHelper.executeQuery(sql);
//			if (rs.next())
//				numNewDoc = rs.getInt(1);
//		} catch (Exception e) {
//		} finally {
//			mysqlHelper.close();
//		}
//		return numNewDoc;
//	}
//
//	public void setNumNewDoc(int numNewDoc) {
//		this.numNewDoc = numNewDoc;
//	}
//
//	public ArrayList<Approvedoc> getAllNewDoc() {
//		getCheck();
//		mysqlHelper.open();
//		allNewDoc.clear();
//		FacesContext f = FacesContext.getCurrentInstance();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		Employee em = (Employee) ss.getAttribute("Employee");
//		try {
//			String sql = "select * from approvedoc where ISNULL(approvedoc.IDGroupApprove)";
//			ResultSet rs = mysqlHelper.executeQuery(sql);
//			while (rs.next()) {
//
//				Approvedoc ap = new Approvedoc(rs.getInt("IDApproveDoc"),
//						rs.getString("Tile"), rs.getString("Content"),
//						rs.getString("IDEmployee"),
//						rs.getString("IDGroupApprove"),
//						rs.getDate("Timecreate"), rs.getInt("IDStatus"),
//						rs.getInt("IDTypeDoc"), rs.getDate("TimeApprove"),
//						rs.getString("comment"), rs.getString("Description"));
//				if (ap.getiDEmployee().equalsIgnoreCase(em.getIdemployee()))
//					allNewDoc.add(ap);
//
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}
//		return allNewDoc;
//	}
//
//	public void setAllNewDoc(ArrayList<Approvedoc> allNewDoc) {
//		this.allNewDoc = allNewDoc;
//	}
//
//	public MySqlDataAccessHelper getMysqlHelper() {
//		return mysqlHelper;
//	}
//
//	public void setMysqlHelper(MySqlDataAccessHelper mysqlHelper) {
//		this.mysqlHelper = mysqlHelper;
//	}
//
//	public int getCurrentIndex() {
//		return currentIndex;
//	}
//
//	public void setCurrentIndex(int currentIndex) {
//		this.currentIndex = currentIndex;
//	}
//
//	public String getScript() {
//		return script;
//	}
//
//	public void setScript(String script) {
//		this.script = script;
//	}
//
//	public Approvedoc getCurrentSelectApprovedoc() {
//		return currentSelectApprovedoc;
//	}
//
//	public void setCurrentSelectApprovedoc(Approvedoc currentSelectApprovedoc) {
//		this.currentSelectApprovedoc = currentSelectApprovedoc;
//	}
//
//	public String getStrErr() {
//		return strErr;
//	}
//
//	public void setStrErr(String strErr) {
//		this.strErr = strErr;
//	}
//
//	public void checkAddReceiver(ActionEvent e) {
//		// if (currentSelectApprovedoc != null) {
////		 HttpSession sss = (HttpSession) FacesContext.getCurrentInstance()
////		 .getExternalContext().getSession(true);
//		// ss.setAttribute("IDApprove",
//		// currentSelectApprovedoc.getiDApproveDoc());
//		// setScript("RichFaces.ui.PopupPanel.hidePopupPanel('popup');openWin('changeModifyReceiver.jsf',1000,760,'modifyReceiver');");
//		// } else {
//		// setStrErr("no doc select");
//		// setScript("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
//		// }
//		//if(allDocSelect.size()==0)return;
//		if (allDocSelect.size() > 0) {
//			HttpSession ss = (HttpSession) FacesContext.getCurrentInstance()
//					.getExternalContext().getSession(true);
//			ss.setAttribute("alldoc", allDocSelect);
//			setScript("RichFaces.ui.PopupPanel.hidePopupPanel('popup');openWin('/ERPApprove/addApproverDocument.jsf',1100,700,'modifyReceiver');");
//		} else {
//			setStrErr(getUtilInitLang().getNodocSelected());
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
//		}
//		
//	}
//
//	public void changeSelectDoc(AjaxBehaviorEvent e) {
//		FacesContext f = FacesContext.getCurrentInstance();
////		UIExtendedDataTable table = (UIExtendedDataTable) f.getViewRoot()
////				.findComponent("form1:table");
////		List<UIComponent> it = table.getChildren();
////		UIColumn columnCheck = (UIColumn) it.get(0);
////		List<UIComponent> listComp = columnCheck.getChildren();
////		HtmlSelectBooleanCheckbox check = (HtmlSelectBooleanCheckbox) listComp
////				.get(0);
////		HtmlSelectBooleanCheckbox compCheckBox = (HtmlSelectBooleanCheckbox) table
////				.findComponent(check.getId());
////		Boolean value1 = (Boolean) compCheckBox.getValue();
////		Approvedoc ap = (Approvedoc) table.getRowData();
////
////		if (!value1) {
////			allDocSelect.remove(ap);
////		} else {
////			if (!allDocSelect.contains(ap)) {
////				allDocSelect.add(ap);
////			}
////		}
////		HtmlSelectBooleanCheckbox check=(HtmlSelectBooleanCheckbox)f.getViewRoot().findComponent(getCheckBoxClientId());
////		System.out.println("Check :"+check.getValue());
//		Approvedoc ap = (Approvedoc) e.getComponent().getAttributes().get("approvedoc");
//		if(allDocSelect.contains(ap)){
//			allDocSelect.remove(ap);
//		}else{
//			allDocSelect.add(ap);
//		}
//		
//	}
//	public String getCheckBoxClientId() {
//		FacesContext context = FacesContext.getCurrentInstance();
//		UIViewRoot root = context.getViewRoot();
//
//		final String componentId = "checkBox";
//		UIComponent c = findComponent(root, componentId);
//		return c.getClientId(context);
//	}
//
//	private UIComponent findComponent(UIComponent c, String id) {
//		if (id.equals(c.getId())) {
//			return c;
//		}
//		Iterator<UIComponent> kids = c.getFacetsAndChildren();
//		while (kids.hasNext()) {
//			UIComponent found = findComponent(kids.next(), id);
//			if (found != null) {
//				return found;
//			}
//		}
//		return null;
//	}
//	public void checkDeleteNewDoc(ActionEvent e) {
//		//if(allDocSelect.size()==0)return;
//		if (allDocSelect.size() <= 0) {
//			setStrErr(getUtilInitLang().getErrNoDocDelete());
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('pErrDelete')");
//		} else {
//			setStrErr(getUtilInitLang().getMessDelete());
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('pDelete')");
//		}
//	}
//
//	public void deleteDoc(ActionEvent e) {
//		try {
//			mysqlHelper.open();
//			for (Approvedoc ap : allDocSelect) {
//				String sql = "delete from approvedoc where IDApproveDoc="
//						+ ap.getiDApproveDoc();
//				mysqlHelper.executeUpdate(sql);
//			}
//		} catch (Exception ex) {
//
//		} finally {
//			check = false;
//			setScript("");
//			allDocSelect.clear();
//			mysqlHelper.close();
//		}
//	}
//
//	public void checkEdit(ActionEvent e) {
//		//if(allDocSelect.size()==0)return;
//		FacesContext f = FacesContext.getCurrentInstance();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		if (allDocSelect.size() > 0) {
//			ss.setAttribute("flagRewrite", new Boolean(true));
//			ss.setAttribute("Approvedoc", allDocSelect.get(0));
//			setScript("openWin('/ERPApprove/editDoc.jsf',1000,760,'EditDoc')");
//		} else {
//			setStrErr(getUtilInitLang().getErrEditdoc());
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('pErrEdit')");
//		}
//	}
//
//	public void onDbClickNewDoc() {
//		// setScript("openWin('changeModifyReceiver.jsf',1000,760,'modifyReceiver');");
//	}
//
//	public void clickNewDoc() {
//		// currentSelectApprovedoc = allNewDoc.get(this.getCurrentIndex());
//	}
//
//	public boolean getCheck() {
//		return check;
//	}
//
//	public void setCheck(boolean check) {
//		this.check = check;
//	}
//
//	public ArrayList<Approvedoc> getAllDocSelect() {
//		return allDocSelect;
//	}
//
//	public void setAllDocSelect(ArrayList<Approvedoc> allDocSelect) {
//		this.allDocSelect = allDocSelect;
//	}
//}
